<template>
  <el-dialog
    :title="!dataForm.bh ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="类型" prop="type">
      <el-input v-model="dataForm.type" placeholder="类型"></el-input>
    </el-form-item>
    <el-form-item label="登录号" prop="dlh">
      <el-input v-model="dataForm.dlh" placeholder="登录号"></el-input>
    </el-form-item>
    <el-form-item label="受理日期" prop="slrq">
      <el-input v-model="dataForm.slrq" placeholder="受理日期"></el-input>
    </el-form-item>
    <el-form-item label="用户名称" prop="yhmc">
      <el-input v-model="dataForm.yhmc" placeholder="用户名称"></el-input>
    </el-form-item>
    <el-form-item label="用户地址" prop="yhdz">
      <el-input v-model="dataForm.yhdz" placeholder="用户地址"></el-input>
    </el-form-item>
    <el-form-item label="申请容量" prop="sqrl">
      <el-input v-model="dataForm.sqrl" placeholder="申请容量"></el-input>
    </el-form-item>
    <el-form-item label="已有容量" prop="yyrl">
      <el-input v-model="dataForm.yyrl" placeholder="已有容量"></el-input>
    </el-form-item>
    <el-form-item label="施工组" prop="sgz">
      <el-input v-model="dataForm.sgz" placeholder="施工组"></el-input>
    </el-form-item>
    <el-form-item label="服务站" prop="fwz">
      <el-input v-model="dataForm.fwz" placeholder="服务站"></el-input>
    </el-form-item>
    <el-form-item label="客户经理" prop="khzl">
      <el-input v-model="dataForm.khzl" placeholder="客户经理"></el-input>
    </el-form-item>
    <el-form-item label="现场勘察时间" prop="kcsj">
      <el-input v-model="dataForm.kcsj" placeholder="现场勘察时间"></el-input>
    </el-form-item>
    <el-form-item label="供电方案答复时间" prop="dfsj">
      <el-input v-model="dataForm.dfsj" placeholder="供电方案答复时间"></el-input>
    </el-form-item>
    <el-form-item label="领料时间" prop="llsj">
      <el-input v-model="dataForm.llsj" placeholder="领料时间"></el-input>
    </el-form-item>
    <el-form-item label="物料明细" prop="wlmx">
      <el-input v-model="dataForm.wlmx" placeholder="物料明细"></el-input>
    </el-form-item>
    <el-form-item label="有工程开工时间（无工程报装）" prop="kgsj">
      <el-input v-model="dataForm.kgsj" placeholder="有工程开工时间（无工程报装）"></el-input>
    </el-form-item>
    <el-form-item label="完工时间（有工装表箱安装）" prop="wgsj">
      <el-input v-model="dataForm.wgsj" placeholder="完工时间（有工装表箱安装）"></el-input>
    </el-form-item>
    <el-form-item label="装表接电时间" prop="jdsj">
      <el-input v-model="dataForm.jdsj" placeholder="装表接电时间"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="zt">
      <el-input v-model="dataForm.zt" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="归档时间" prop="gdsj">
      <el-input v-model="dataForm.gdsj" placeholder="归档时间"></el-input>
    </el-form-item>
    <el-form-item label="提报立项资料时间" prop="lxsj">
      <el-input v-model="dataForm.lxsj" placeholder="提报立项资料时间"></el-input>
    </el-form-item>
    <el-form-item label="合并打包时间" prop="hbsj">
      <el-input v-model="dataForm.hbsj" placeholder="合并打包时间"></el-input>
    </el-form-item>
    <el-form-item label="未本人联系原因" prop="wlxyy">
      <el-input v-model="dataForm.wlxyy" placeholder="未本人联系原因"></el-input>
    </el-form-item>
    <el-form-item label="是否现场勘察，是否有录像记录" prop="bz">
      <el-input v-model="dataForm.bz" placeholder="是否现场勘察，是否有录像记录"></el-input>
    </el-form-item>
    <el-form-item label="实际现场堪察人" prop="kcr">
      <el-input v-model="dataForm.kcr" placeholder="实际现场堪察人"></el-input>
    </el-form-item>
    <el-form-item label="未本人现场勘察原因" prop="wkcyy">
      <el-input v-model="dataForm.wkcyy" placeholder="未本人现场勘察原因"></el-input>
    </el-form-item>
    <el-form-item label="停止原因概述" prop="tzyy">
      <el-input v-model="dataForm.tzyy" placeholder="停止原因概述"></el-input>
    </el-form-item>
    <el-form-item label="停止具体描述" prop="tzms">
      <el-input v-model="dataForm.tzms" placeholder="停止具体描述"></el-input>
    </el-form-item>
    <el-form-item label="服务站和客户最新沟通时间" prop="zxggsj">
      <el-input v-model="dataForm.zxggsj" placeholder="服务站和客户最新沟通时间"></el-input>
    </el-form-item>
    <el-form-item label="沟通人和沟通方式" prop="gtr">
      <el-input v-model="dataForm.gtr" placeholder="沟通人和沟通方式"></el-input>
    </el-form-item>
    <el-form-item label="客户需求和客户反应" prop="khxq">
      <el-input v-model="dataForm.khxq" placeholder="客户需求和客户反应"></el-input>
    </el-form-item>
    <el-form-item label="需协调事宜" prop="xtsy">
      <el-input v-model="dataForm.xtsy" placeholder="需协调事宜"></el-input>
    </el-form-item>
    <el-form-item label="注销佐证中的原因" prop="zzyy">
      <el-input v-model="dataForm.zzyy" placeholder="注销佐证中的原因"></el-input>
    </el-form-item>
    <el-form-item label="详细描述注销原因" prop="zxxxyy">
      <el-input v-model="dataForm.zxxxyy" placeholder="详细描述注销原因"></el-input>
    </el-form-item>
    <el-form-item label="有无高压配套" prop="gyptbz">
      <el-input v-model="dataForm.gyptbz" placeholder="有无高压配套"></el-input>
    </el-form-item>
    <el-form-item label="高压配套内容" prop="gyptnr">
      <el-input v-model="dataForm.gyptnr" placeholder="高压配套内容"></el-input>
    </el-form-item>
    <el-form-item label="高压配套完成时间" prop="gyptwcsj">
      <el-input v-model="dataForm.gyptwcsj" placeholder="高压配套完成时间"></el-input>
    </el-form-item>
    <el-form-item label="客户联系人" prop="lxr">
      <el-input v-model="dataForm.lxr" placeholder="客户联系人"></el-input>
    </el-form-item>
    <el-form-item label="客户联系电话" prop="lxrdh">
      <el-input v-model="dataForm.lxrdh" placeholder="客户联系电话"></el-input>
    </el-form-item>
    <el-form-item label="是否有10kv高压配套" prop="10kvbz">
      <el-input v-model="dataForm.kvbz" placeholder="是否有10kv高压配套"></el-input>
    </el-form-item>
    <el-form-item label="电建项目经理" prop="jl">
      <el-input v-model="dataForm.jl" placeholder="电建项目经理"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          bh: 0,
          type: '',
          dlh: '',
          slrq: '',
          yhmc: '',
          yhdz: '',
          sqrl: '',
          yyrl: '',
          sgz: '',
          fwz: '',
          khzl: '',
          kcsj: '',
          dfsj: '',
          llsj: '',
          wlmx: '',
          kgsj: '',
          wgsj: '',
          jdsj: '',
          zt: '',
          gdsj: '',
          lxsj: '',
          hbsj: '',
          wlxyy: '',
          bz: '',
          kcr: '',
          wkcyy: '',
          tzyy: '',
          tzms: '',
          zxggsj: '',
          gtr: '',
          khxq: '',
          xtsy: '',
          zzyy: '',
          zxxxyy: '',
          gyptbz: '',
          gyptnr: '',
          gyptwcsj: '',
          lxr: '',
          lxrdh: '',
          kvbz: '',
          jl: ''
        },
        dataRule: {
          type: [
            { required: true, message: '类型不能为空', trigger: 'blur' }
          ],
          dlh: [
            { required: true, message: '登录号不能为空', trigger: 'blur' }
          ],
          slrq: [
            { required: true, message: '受理日期不能为空', trigger: 'blur' }
          ],
          yhmc: [
            { required: true, message: '用户名称不能为空', trigger: 'blur' }
          ],
          yhdz: [
            { required: true, message: '用户地址不能为空', trigger: 'blur' }
          ],
          sqrl: [
            { required: true, message: '申请容量不能为空', trigger: 'blur' }
          ],
          yyrl: [
            { required: true, message: '已有容量不能为空', trigger: 'blur' }
          ],
          sgz: [
            { required: true, message: '施工组不能为空', trigger: 'blur' }
          ],
          fwz: [
            { required: true, message: '服务站不能为空', trigger: 'blur' }
          ],
          khzl: [
            { required: true, message: '客户经理不能为空', trigger: 'blur' }
          ],
          kcsj: [
            { required: true, message: '现场勘察时间不能为空', trigger: 'blur' }
          ],
          dfsj: [
            { required: true, message: '供电方案答复时间不能为空', trigger: 'blur' }
          ],
          llsj: [
            { required: true, message: '领料时间不能为空', trigger: 'blur' }
          ],
          wlmx: [
            { required: true, message: '物料明细不能为空', trigger: 'blur' }
          ],
          kgsj: [
            { required: true, message: '有工程开工时间（无工程报装）不能为空', trigger: 'blur' }
          ],
          wgsj: [
            { required: true, message: '完工时间（有工装表箱安装）不能为空', trigger: 'blur' }
          ],
          jdsj: [
            { required: true, message: '装表接电时间不能为空', trigger: 'blur' }
          ],
          zt: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          gdsj: [
            { required: true, message: '归档时间不能为空', trigger: 'blur' }
          ],
          lxsj: [
            { required: true, message: '提报立项资料时间不能为空', trigger: 'blur' }
          ],
          hbsj: [
            { required: true, message: '合并打包时间不能为空', trigger: 'blur' }
          ],
          wlxyy: [
            { required: true, message: '未本人联系原因不能为空', trigger: 'blur' }
          ],
          bz: [
            { required: true, message: '是否现场勘察，是否有录像记录不能为空', trigger: 'blur' }
          ],
          kcr: [
            { required: true, message: '实际现场堪察人不能为空', trigger: 'blur' }
          ],
          wkcyy: [
            { required: true, message: '未本人现场勘察原因不能为空', trigger: 'blur' }
          ],
          tzyy: [
            { required: true, message: '停止原因概述不能为空', trigger: 'blur' }
          ],
          tzms: [
            { required: true, message: '停止具体描述不能为空', trigger: 'blur' }
          ],
          zxggsj: [
            { required: true, message: '服务站和客户最新沟通时间不能为空', trigger: 'blur' }
          ],
          gtr: [
            { required: true, message: '沟通人和沟通方式不能为空', trigger: 'blur' }
          ],
          khxq: [
            { required: true, message: '客户需求和客户反应不能为空', trigger: 'blur' }
          ],
          xtsy: [
            { required: true, message: '需协调事宜不能为空', trigger: 'blur' }
          ],
          zzyy: [
            { required: true, message: '注销佐证中的原因不能为空', trigger: 'blur' }
          ],
          zxxxyy: [
            { required: true, message: '详细描述注销原因不能为空', trigger: 'blur' }
          ],
          gyptbz: [
            { required: true, message: '有无高压配套不能为空', trigger: 'blur' }
          ],
          gyptnr: [
            { required: true, message: '高压配套内容不能为空', trigger: 'blur' }
          ],
          gyptwcsj: [
            { required: true, message: '高压配套完成时间不能为空', trigger: 'blur' }
          ],
          lxr: [
            { required: true, message: '客户联系人不能为空', trigger: 'blur' }
          ],
          lxrdh: [
            { required: true, message: '客户联系电话不能为空', trigger: 'blur' }
          ],
          kvbz: [
            { required: true, message: '是否有10kv高压配套不能为空', trigger: 'blur' }
          ],
          jl: [
            { required: true, message: '电建项目经理不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.bh = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.bh) {
            this.$http({
              url: this.$http.adornUrl(`/generator/task/info/${this.dataForm.bh}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.type = data.task.type
                this.dataForm.dlh = data.task.dlh
                this.dataForm.slrq = data.task.slrq
                this.dataForm.yhmc = data.task.yhmc
                this.dataForm.yhdz = data.task.yhdz
                this.dataForm.sqrl = data.task.sqrl
                this.dataForm.yyrl = data.task.yyrl
                this.dataForm.sgz = data.task.sgz
                this.dataForm.fwz = data.task.fwz
                this.dataForm.khzl = data.task.khzl
                this.dataForm.kcsj = data.task.kcsj
                this.dataForm.dfsj = data.task.dfsj
                this.dataForm.llsj = data.task.llsj
                this.dataForm.wlmx = data.task.wlmx
                this.dataForm.kgsj = data.task.kgsj
                this.dataForm.wgsj = data.task.wgsj
                this.dataForm.jdsj = data.task.jdsj
                this.dataForm.zt = data.task.zt
                this.dataForm.gdsj = data.task.gdsj
                this.dataForm.lxsj = data.task.lxsj
                this.dataForm.hbsj = data.task.hbsj
                this.dataForm.wlxyy = data.task.wlxyy
                this.dataForm.bz = data.task.bz
                this.dataForm.kcr = data.task.kcr
                this.dataForm.wkcyy = data.task.wkcyy
                this.dataForm.tzyy = data.task.tzyy
                this.dataForm.tzms = data.task.tzms
                this.dataForm.zxggsj = data.task.zxggsj
                this.dataForm.gtr = data.task.gtr
                this.dataForm.khxq = data.task.khxq
                this.dataForm.xtsy = data.task.xtsy
                this.dataForm.zzyy = data.task.zzyy
                this.dataForm.zxxxyy = data.task.zxxxyy
                this.dataForm.gyptbz = data.task.gyptbz
                this.dataForm.gyptnr = data.task.gyptnr
                this.dataForm.gyptwcsj = data.task.gyptwcsj
                this.dataForm.lxr = data.task.lxr
                this.dataForm.lxrdh = data.task.lxrdh
                this.dataForm.kvbz = data.task.kvbz
                this.dataForm.jl = data.task.jl
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/generator/task/${!this.dataForm.bh ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'bh': this.dataForm.bh || undefined,
                'type': this.dataForm.type,
                'dlh': this.dataForm.dlh,
                'slrq': this.dataForm.slrq,
                'yhmc': this.dataForm.yhmc,
                'yhdz': this.dataForm.yhdz,
                'sqrl': this.dataForm.sqrl,
                'yyrl': this.dataForm.yyrl,
                'sgz': this.dataForm.sgz,
                'fwz': this.dataForm.fwz,
                'khzl': this.dataForm.khzl,
                'kcsj': this.dataForm.kcsj,
                'dfsj': this.dataForm.dfsj,
                'llsj': this.dataForm.llsj,
                'wlmx': this.dataForm.wlmx,
                'kgsj': this.dataForm.kgsj,
                'wgsj': this.dataForm.wgsj,
                'jdsj': this.dataForm.jdsj,
                'zt': this.dataForm.zt,
                'gdsj': this.dataForm.gdsj,
                'lxsj': this.dataForm.lxsj,
                'hbsj': this.dataForm.hbsj,
                'wlxyy': this.dataForm.wlxyy,
                'bz': this.dataForm.bz,
                'kcr': this.dataForm.kcr,
                'wkcyy': this.dataForm.wkcyy,
                'tzyy': this.dataForm.tzyy,
                'tzms': this.dataForm.tzms,
                'zxggsj': this.dataForm.zxggsj,
                'gtr': this.dataForm.gtr,
                'khxq': this.dataForm.khxq,
                'xtsy': this.dataForm.xtsy,
                'zzyy': this.dataForm.zzyy,
                'zxxxyy': this.dataForm.zxxxyy,
                'gyptbz': this.dataForm.gyptbz,
                'gyptnr': this.dataForm.gyptnr,
                'gyptwcsj': this.dataForm.gyptwcsj,
                'lxr': this.dataForm.lxr,
                'lxrdh': this.dataForm.lxrdh,
                '10kvbz': this.dataForm.kvbz,
                'jl': this.dataForm.jl
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
